package cn.mayaslight.common.dto;

import cn.mayaslight.common.cache.RespStatusCodeCache;
import cn.mayaslight.common.common.BaseConsts;
import cn.mayaslight.common.pojo.RespStatusCode;
import cn.mayaslight.common.springbean.CacheManager;

public class R {

	private boolean errsts;
	private String errmsg;
	private Object errdata;
	private String errcode;

	public R(String errcode) {
		this.errcode = errcode;
	}

	public R(String errSts, String errmsg) {
		this.errcode = errSts;
		this.errmsg = errmsg;
	}

	public R(RespStatusCode respStatuCode) {
		this.errcode = respStatuCode.getCode();
		this.errmsg = respStatuCode.getMessage();
	}

	public R(RespStatusCode respStatuCode, String errmsg) {
		this.errcode = respStatuCode.getCode();
		this.errmsg = errmsg;
	}

	public R(RespStatusCode respStatuCode, Object errdata) {
		this.errcode = respStatuCode.getCode();
		this.errmsg = respStatuCode.getMessage();
		this.errdata = errdata;
	}

	public R(RespStatusCode respStatuCode, String errmsg, Object errdata) {
		this.errcode = respStatuCode.getCode();
		this.errmsg = errmsg;
		this.errdata = errdata;
	}

	public static R success() {
		return new R(CacheManager.loadUniqueByKey(RespStatusCodeCache.class, BaseConsts.RespCodeKeys.BUSINESS_KEY));
	}

	public static R success(Object errdata) {
		return new R(CacheManager.loadUniqueByKey(RespStatusCodeCache.class, BaseConsts.RespCodeKeys.BUSINESS_KEY), errdata);
	}

	public static R error() {
		return new R(CacheManager.loadUniqueByKey(RespStatusCodeCache.class, BaseConsts.RespCodeKeys.ERROR_KEY));
	}

	public static R error(String errmsg) {
		return new R(CacheManager.loadUniqueByKey(RespStatusCodeCache.class, BaseConsts.RespCodeKeys.ERROR_KEY), errmsg);
	}

	public static R error(long businessId) {
		return new R(CacheManager.loadUniqueByKey(RespStatusCodeCache.class, BaseConsts.RespCodeKeys.BUSINESS_KEY + "$$" + businessId));
	}

	public static R error(long businessId, Object errdata) {
		return new R(CacheManager.loadUniqueByKey(RespStatusCodeCache.class, BaseConsts.RespCodeKeys.BUSINESS_KEY + "$$" + businessId), errdata);
	}

	public boolean isErrsts() {
		return errsts;
	}

	public void setErrsts(boolean errsts) {
		this.errsts = errsts;
	}

	public String getErrmsg() {
		return errmsg;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}

	public Object getErrdata() {
		return errdata;
	}

	public void setErrdata(Object errdata) {
		this.errdata = errdata;
	}

	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

}
